How to make a stand-alone white/brown/grey/pink noise generator

Kinja'd!!! "Akio Ohtori - RIP Oppo" (akioohtori)
03/19/2020 at 11:07 • Filed to: None

Kinja'd!!!3 Kinja'd!!! 10
Kinja'd!!!

Hey Oppo, since a lot of us are cohabitating these days, I thought I’d share with you my favorite “life hack” of the last couple years: A white noise system. It helps keep distractions down and drown out your dogs/kids/refrigerator/zombies scratching at the door.

Disclaimer: It has been over a year since I’ve made one of these, so some of the steps are a little fuzzy. If one of you does this let me know where the snags are and I’ll update the post as we go!

Now, white noise is actually a defined term meaning, approximately, “a random signal having equal intensity at different frequencies, giving it a constant power spectral density.” So we’re not building that.

Actually what we are building is arbitrary sound playing device, that we then load our favorite white noise sound byte into. Basically my setup is a Raspberry Pi, a set of speakers, and... that is it.

Basically this will consist of:

Sound playing device (In this example a Raspberry Pi)

Speakers

Sound file(s) of your choosing

Python script

USB Sound Card (Optional)

My system is cobbled together from a couple of guides, but here is the jist:

Step 1: Set-up your device

I’m using a Raspberry Pi, but this guide could be used for any Linux based device. I’m not covering how to get the OS running on whatever device you choose as there are !!!error: Indecipherable SUB-paragraph formatting!!! .

Power on the device and install !!!error: Indecipherable SUB-paragraph formatting!!! and !!!error: Indecipherable SUB-paragraph formatting!!! via your favorite software manager.

Load the following code into !!!error: Indecipherable SUB-paragraph formatting!!! in a directory of your choosing. In this case the file is noise.py and the directory is /home/pi/

import pygame

pygame.init()
pygame.mixer.init()

pygame.mixer.music.load(‘[your/path/here.wav’)
pygame.mixer.music.play(-1) #the -1 permits continuous playback

pygame.event.wait()

Save that as, for example, noise.py

This code originally actually selected a file at random from a list and played that, but that wasn’t really my jam. Unfortunately I can’t find the OP to give credit to, so if anyone runs across it in their internet travels let me know and I will update with a link.

You’ll need to point the script to your noise file on device.

Step 1.5: What noise to play?

The world is your oyster and there are plenty of places you can download ambient noise files, but here is how it worked out for me:

In the past, I’ve like brown noise (lol). It is deeper than white and sounds more like water to me. Allegedly pink noise is the best for sound curtains, but in practice I found it too harsh and tinny. Maybe I was playing it too loud? Maybe my speakers were too shitty.

What I’ve found makes the ideal sound for me is:

Mostly low frequency

Little to no variation

No actual water sounds or thunder

Very long file (~24 hours works best)

By far my favorite is !!!error: Indecipherable SUB-paragraph formatting!!! :

!!! UNKNOWN CONTENT TYPE !!!

The sound of the USS Enterprise’s engine idling. I know, sounds silly but actually it is prefect white noise. Just listen to it!

The full 24 hour MP3/WAV is a little over a gig (don’t be fooled by the OGG, it is only a few hours long) but well worth it.

Whatever sound you choose, I suggest you open it Audacity or whatever audio editing program you like. Basically you’ll want to make sure there isn’t a massive gap at the beginning/ end of the file that would be audible. You can also make modifications to ensure the file loops seamlessly, though in practice I don’t mind the audio glitch every 24 hours. If your sound file is very short, I suggest making it at least 4 hours long, preferably much longer, to reduce the chances for errors.

Step 2: Testing your script and troubleshooting audio

Next up you’ll need to make your noise.py executable. That is easy by just saying chmod +x noise.py . You can then execute the script by running it in python python noise.py , assuming you have speakers connected. If you don’t... well now is the time.

HOWEVER, I’ve found there are a couple problems with this.

First off, by default the sound output is set to 100% and that doesn’t seem to work well. Before I run the script I’ll run amixer set PCM — 100 , which seems to make everything better. (That is a double dash between PCM and 100 but Kinja is formatting it weird.)

So try that first and see where it takes you. IIRC the — 100 is telling amixer to set the output to 10.0%.

Even when doing that, with the default sound output from a Raspberry Pi I’d get unwanted noise, random clicks, and interference. A lot of this came down to the power supply to the Pi. If you use a bad supply that apparently causes it to introduce artifacts into the audio. Also if you power USB speakers off the Pi you’re asking for trouble.

Even with all of that in an ideal configuration, you can still get clicks, pops, and other annoying artifacts in the output. There are a lot of things to google to fix it, though !!!error: Indecipherable SUB-paragraph formatting!!! seemed to help me the most.

Or, the solution to all of this, apparently, is to use a USB sound card. I haven’t done it for this application as once I get these working I tend to never touch them again. (I have two in the house both of which have been running for well over a year...) If you continue to have audio problems a USB sound card may be the solution.

Step 3: Auto-running the script

There are a ton of different ways to auto-run code in Linux and I suggest you look them all up and choose one that works best for you.

I chose the deprecated rc.local method because it was easy and straightforward. All I did was add the following two lines to my rc.local file... I think?

amixer set PCM — 100
python /home/pi/noise.py &

The & at the end of that command is very important. If you don’t have that, execution will pause waiting for that code to finish executing. If you recall, we set that code to never finish executing.... so you’ll get some weirdness.

Anyway, via your favorite method make that puppy auto-run and, if you’re sure you haven’t messed it up, reboot and see what happens.

Step 99: Other Considerations

Umm... well what else is there? As I mentioned above I’ve had two of these running for several years without issues other than having to wrestle with audio clicks, pops, etc. They seem to survive reboot gracefully, which is surprising for a Pi.

I would say there is no need to use an expensive new Pi 4. Just any linux based machine you can find. If you have a Pi 2 or 3 lying around, this might be a good use for it. I personally love the Beagle Bone series, but as they’re a little pricier I’m not sure I can recommend them for this application.

I’m sure there is a way to do this in another OS, but I’m sure I don’t know what it is.

I would say DO NOT connect this to your network permanently. I say that because after I get these running I don’t touch them, therefore they get behind on their security updates and quickly would become a liability on the network. I’d also write down any static IP settings and login information on the Pi itself so if you need to make a change in a year or so you can still get in to the poor thing.

I hope this works out for you guys!


DISCUSSION (10)


Kinja'd!!! Rusty Vandura - www.tinyurl.com/keepoppo > Akio Ohtori - RIP Oppo
03/19/2020 at 11:22

Kinja'd!!!0

Also, recordings of rain falling on a river work nicely. And Bose QC headphones.


Kinja'd!!! Tripper > Akio Ohtori - RIP Oppo
03/19/2020 at 11:23

Kinja'd!!!1

Hey neat post! I know I have a spare Pi around here somewhere. If I find it I’ma do it.

Also thanks for reminding me to update my linux box!!!


Kinja'd!!! Akio Ohtori - RIP Oppo > Rusty Vandura - www.tinyurl.com/keepoppo
03/19/2020 at 11:27

Kinja'd!!!0

Nice. I also considered pulling the audio out of this one , but for stupid reasons the sound of rain makes me anxious.


Kinja'd!!! Thomas Donohue > Akio Ohtori - RIP Oppo
03/19/2020 at 11:27

Kinja'd!!!1

Personally, I prefer the White Stripes.


Kinja'd!!! CalzoneGolem > Akio Ohtori - RIP Oppo
03/19/2020 at 11:35

Kinja'd!!!1

I’m saving this to reference later. 


Kinja'd!!! facw > Akio Ohtori - RIP Oppo
03/19/2020 at 11:37

Kinja'd!!!1

This reminds me, I need to figure out how to make my phone play a looping track of silence when connected to my car bluetooth (if it’s not playing something, waking up the connection takes to long and the start of GPS commands get cut off)


Kinja'd!!! PowderHound > Akio Ohtori - RIP Oppo
03/19/2020 at 11:38

Kinja'd!!!2

Brown noise… lol


Kinja'd!!! Akio Ohtori - RIP Oppo > facw
03/19/2020 at 11:48

Kinja'd!!!0

Yeah I have also found that to be a problem.  I think audacity would let you generate a file of just silence to play.


Kinja'd!!! Rusty Vandura - www.tinyurl.com/keepoppo > Akio Ohtori - RIP Oppo
03/19/2020 at 12:23

Kinja'd!!!1

I don’t know your musical tastes, but I’ve been listening to “chill hop” on Spotify. I seeded a station with an artist called Proleter. The beats are all very similar, but good to block out the world and tap your foot. I am very  selective about music, so finding this and it works is unusual for me.


Kinja'd!!! Klaus Schmoll > Akio Ohtori - RIP Oppo
03/19/2020 at 18:34

Kinja'd!!!0

The idea of using white noise to concentrate when doing home office with the need to cancel out dog, children, family noises is an interestind idea.

I first encountered the use of white noise through Hunter S. T hompson’s books. He painted the picture of arriving in a different time zone completely hung over and needing a nap in a hotel room while there are car horns, traffic and the usual noises of a busy city outside. His advice was to jam the TV between two stat ions and letting it blast white noise. Still possible in the 70s.

When I was studying at Heidelberg University they were digging up, then laying new pipes and then repaving the street in front of my tiny appartment. Starting at 6 a.m. sharp every morning. As a student I didn’t have to get up that early, so I set my stereo system to a non-existe nt radio station, or basically a free frequency and let it blast white noise. Takes some getting used to, but eventually the brain gets used to it and ca ncels it out. I could sleep in like a baby!